﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Zenject;

namespace QFramework.Fullstack.Example
{
	public class ZenjectFrameworkLayer : IFrameworkLayer
	{
		DiContainer mDiContainer = new DiContainer();

		public DiContainer Container
		{
			get
			{
				return mDiContainer;
			}
		}

		public void Register<T>(object obj)
		{
			mDiContainer.BindInstance<T>((T) obj);
		}

		public T Get<T>() where T : class
		{
			return mDiContainer.Resolve<T>();
		}

		public void Clear()
		{
			mDiContainer = new DiContainer();
		}
	}
	
	public static class ZenjectFrameworkLayerExtensions
	{
		public static void Register<TAbstract, TImplement>(this IFrameworkLayer self) where TImplement : TAbstract
		{
			var zenjectFrameworkLayer = self as ZenjectFrameworkLayer;
			zenjectFrameworkLayer.Container.Bind<TAbstract>().To<TImplement>().AsSingle();
		}
	}
}
